<?php
// ----- >> Extends From Template
class thisPDF extends PDF{
	function Header(){}
	function Footer(){}
}

function terbilang_get_valid($str,$from,$to,$min=1,$max=9){
      $val=false;
      $from=($from<0)?0:$from;
      for ($i=$from;$i<$to;$i++){
        if (((int) $str{$i}>=$min)&&((int) $str{$i}<=$max)) $val=true;
      }
      return $val;
  } 

  function terbilang_get_str($i,$str,$len){
      $numA=array("","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan");
      $numB=array("","se","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numC=array("","satu ","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numD=array(0=>"puluh",1=>"belas",2=>"ratus",4=>"ribu", 7=>"juta", 10=>"milyar", 13=>"triliun");
      $buf="";
      $pos=$len-$i;
      switch($pos){
        case 1:
            if (!terbilang_get_valid($str,$i-1,$i,1,1))
              $buf=$numA[(int) $str{$i}];
          break;
        case 2: case 5: case 8: case 11: case 14:
            if ((int) $str{$i}==1){
              if ((int) $str{$i+1}==0)
                $buf=($numB[(int) $str{$i}]).($numD[0]);
              else
                $buf=($numB[(int) $str{$i+1}]).($numD[1]);
            }
            else if ((int) $str{$i}>1){
                $buf=($numB[(int) $str{$i}]).($numD[0]);
            }       
          break;
        case 3: case 6: case 9: case 12: case 15:
            if ((int) $str{$i}>0){
                $buf=($numB[(int) $str{$i}]).($numD[2]);
            }
          break;
        case 4: case 7: case 10: case 13:
            if (terbilang_get_valid($str,$i-2,$i)){
              if (!terbilang_get_valid($str,$i-1,$i,1,1))
                $buf=$numC[(int) $str{$i}].($numD[$pos]);
              else
                $buf=$numD[$pos];
            }           else if((int) $str{$i}>0){
              if ($pos==4)
                $buf=($numB[(int) $str{$i}]).($numD[$pos]);
              else
                $buf=($numC[(int) $str{$i}]).($numD[$pos]);
            }
          break;
      }
      return $buf;
  }
  function toTerbilang($nominal){
      $buf="";
      $str=$nominal."";
      $len=strlen($str);
      
      for ($i=0;$i<$len;$i++){
        $buf=trim($buf)." ".terbilang_get_str($i,$str,$len);
      }
      return trim($buf);
  }

// ----- >> Init
$fpdf = new thisPDF('P','mm','A4');
$fpdf->AddPage();
$fpdf->SetLeftMargin(8);

$fpdf->Ln(0);
$ln_header_y_top	= $fpdf->GetY();

$time = date('d-M-y');

// ----- >> Header
$fpdf->Ln(2);

//$Image = APPPATH . 'file/kstore/logo_primkokas.jpg' ; 
$fpdf->Cell( 30, 20, $fpdf->Image(APPPATH . 'file/media/logo_primkokas.jpg' , $fpdf->GetX(), $fpdf->GetY(), 40.68), 0, 0, 'L', false );
//$fpdf->Ln(20);

$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(70,5,"",0,0,'L');
$fpdf->Cell(0,2,"PRIMER KOPERASI KARYAWAN KRAKATAU STEEL",0,0,'L');
$fpdf->Ln(5);
$fpdf->SetFont('Arial','',10);
$fpdf->Cell(87,5,"",0,0,'L');
$fpdf->Cell(0,2,"Gedung Krakatau Junction Lt. 3, Jl. KH. Yasin Neji Komp. PT KS",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(151,5,"",0,0,'L');
$fpdf->Cell(0,2,"Cilegon - Banten 42435",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(89,5,"",0,0,'L');
$fpdf->Cell(0,2,"Phone +62 (254) 392784, 372289 Fax. + (254) 372290, 398884",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(139,5,"",0,0,'L');
$fpdf->Cell(0,2,"Website : www.primkokas.co.id",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(144,5,"",0,0,'L');
$fpdf->Cell(0,2,"email: info@primkokas.co.id",0,0,'L');
$fpdf->Ln(5);


$fpdf->Line(9, 42, 200-3, 42); // 197mm from each edge


// ----- >> Data Master

$fpdf->Ln(4);

// ----- >> Data Master
//setting judul laporan dan header tabel

//$fpdf->addPage();
//$fpdf->setAutoPageBreak(false);

$fpdf->SetFont('Arial','',10);
$fpdf->Cell(20,5,"Nomor",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(50,5,$no_konfirmasi,0,0,'L');
$fpdf->Ln(4);

$fpdf->Cell(20,5,"Lampiran",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->Cell(20,5,"1 (satu) set.",0,0,'L');
$fpdf->Ln(4);



$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(20,5,"Perihal",0,0,'L');
$fpdf->Cell(2,5,":",0,0,'L');
$fpdf->SetFont('Arial','BU',10);
$fpdf->Cell(60,5,"Laporan Konfirmasi Tagihan",0,0,'L');
$fpdf->Ln(10);

$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(140,5,"Kepada Yth.",0,0,'L');
$fpdf->Ln(5);
$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(140,5,"Bapak/Ibu ".$data['nama_tenant']." ",0,0,'L');
$fpdf->Ln(5);
$fpdf->SetFont('Arial','',10);
$fpdf->Cell(140,5,"".$data['lokasi_tempat']." ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(140,5,"Di Tempat",0,0,'L');
$fpdf->Ln(10);

$fpdf->SetFont('Arial','',10);

 $fpdf->Cell(1,5,"",0,0,'L');
$fpdf->Cell(140,5,"Dengan Hormat, ",0,0,'L');
$fpdf->Ln(8);
$fpdf->Cell(141,5,"Puji syukur ke hadirat Allah SWT teriring doa semoga Bapak/Ibu dalam keadaan ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(141,5,"sehat wal afiat dan senantiasa mendapat lindungan-Nya di dalam menjalankan",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(141,5,"tugas sehari-hari. Amin.",0,0,'L');
$fpdf->Ln(8);
$fpdf->Cell(141,5,"Bersama ini kami selaku Pihak Property Management ingin menyampaikan",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(141,5,"informasi bahwa Bapak/Ibu ".$data['nama_tenant']." belum menyelesaikan tagihan sewa toko no. ".$data['no_toko']." untuk",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(141,5,"periode ".$data['periode_pembayaran']." yaitu sebagai berikut:",0,0,'L');
$fpdf->Ln(8);
$fpdf->SetFont('Arial','',10);

$total_tagihan_sewa = 0;
$x=1;
foreach ($data_detail_sewa as $key => $data_detail_sewa_value) {
          $fpdf->Cell(30,5,"",0,0,'L');
          $fpdf->Cell(5,5,$x.". ",0,0,'L');
          $fpdf->Cell(40,5,"Tagihan Sewa : ",0,0,'L');
          $fpdf->Cell(40,5,$data_detail_sewa_value['periode_pembayaran'],0,0,'L');
          $fpdf->Cell(17.5,5,"Rp. " ,0,0,'L');
          $fpdf->Cell(14,5,number_format($data_detail_sewa_value['harga_sewa']).",- ",0,0,'R');
          $fpdf->Ln(5);
          
          $total_tagihan_sewa = $total_tagihan_sewa + $data_detail_sewa_value['harga_sewa'];

          $x++;
      }


$fpdf->Ln(5);

$total_tagihan_listrik = 0;
$g=1;
foreach ($data_detail_listrik as $key => $data_detail_listrik_value) {
  //var_dump($data_detail_listrik_value['periode_pembayaran']);
          $fpdf->Cell(30,5,"",0,0,'L');
          $fpdf->Cell(5,5,$g.". ",0,0,'L');
         // $fpdf->Cell(35,5,"",0,0,'L');
          $fpdf->Cell(40,5,"Tagihan Listrik : ",0,0,'L');
          $fpdf->Cell(40,5,$data_detail_listrik_value['periode_pembayaran'],0,0,'L');
          $fpdf->Cell(17.5,5,"Rp. " ,0,0,'L');
          $fpdf->Cell(14,5,number_format($data_detail_listrik_value['total_tagihan']).",- ",0,0,'R');
          $fpdf->Ln(5);

          $total_tagihan_listrik = $total_tagihan_listrik + $data_detail_listrik_value['total_tagihan'];
          $g++;
}


$grand_total =  "$total_tagihan_listrik"  + "$total_tagihan_sewa";

$fpdf->Ln(5);
$fpdf->Cell(20,5,"",0,0,'L');
$fpdf->Cell(95,5,"Total Keseluruhan yang harus di bayar",0,0,'L');
$fpdf->Cell(17.5,5,"Rp. " ,0,0,'L');
$fpdf->SetFont('Arial','B',10);
//$fpdf->Cell(14,5,number_format($grand_total['total_tagihan']).",- ",0,0,'R');
   $fpdf->Cell(14,5,number_format($grand_total).",- ",0,0,'R');
$fpdf->Ln(5);
      $fpdf->SetFont("");
      $fpdf->SetFont('Arial','BI',10);
      $fpdf->Cell(20,5,"",0,0,'L');
      $fpdf->Cell(95,5,"# ".toTerbilang($grand_total)." Rupiah #",0,0,'L');
$fpdf->Ln(10);
$fpdf->SetFont('Arial','',10);
$fpdf->Cell(20,5,"",0,0,'L');
$fpdf->Cell(141,5,"Kami harapkan Bapak/Ibu dapat segera menyelesaikan tagihan tersebut sesuai",0,0,'L');
$fpdf->Ln(5);

$fpdf->Cell(20,5,"",0,0,'L');
$fpdf->Cell(141,5,"syarat dan ketentuan yang berlaku.",0,0,'L');
$fpdf->Ln(5);

$fpdf->Cell(20,5,"",0,0,'L');
$fpdf->Cell(141,5,"Demikian pemberitahuan ini kami sampaikan, atas perhatian dan kerjasamanya",0,0,'L');
$fpdf->Ln(5);

$fpdf->Cell(20,5,"",0,0,'L');
$fpdf->Cell(141,5,"diucapkan terima kasih.",0,0,'L');
$fpdf->Ln(15);

$fpdf->SetFont('Arial','',10);
$fpdf->Cell(155,5,"",0,0,'L');
$fpdf->Cell(10,5,"Cilegon, ".$time,0,0,'R');
$fpdf->Ln(7);

$fpdf->Cell(35,5,"",0,0,'L');
$fpdf->Cell(87,5,"Mengetahui ",0,0,'L');
$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(10,5,"PRIMER KOPERASI KARYAWAN ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(133,5,"",0,0,'L');
$fpdf->Cell(10,5,"KRAKATAU STEEL",0,0,'L');
$fpdf->SetFont('');
$fpdf->Ln(25);


//$fpdf->Image(APPPATH . 'file/media/ttd_isp.jpg');
//$fpdf->Ln(5);
$fpdf->Cell(34,5,"",0,0,'L');
$fpdf->SetFont('Arial','BU',10);
$fpdf->Cell(108,5,"Aan Supriana",0,0,'L');
$fpdf->Cell(10,5,"Ngajito",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(15,5,"",0,0,'L');
$fpdf->SetFont('');
$fpdf->Cell(123,5,"Internal Busines & Property Div. Manager",0,0,'L');
$fpdf->Cell(10,5,"Property Div.",0,0,'L');
$fpdf->Ln(10);
$fpdf->SetFont('');
$fpdf->Cell(123,5,"Tembusan : ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(90,5,"    1. Yth. Ketua Umum PRIMKOKAS  ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(90,5,"    2. Yth. IB & Property Div. Mgr ",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(90,5,"    3. Arsip  ",0,0,'L');
$fpdf->Ln(5);




$date = date('d-M-y');
echo $fpdf->Output('Laporan Konfirmasi Tagihan'." "."$date"." ".'.pdf','I');
exit();
?>
<!-- 

 -->